import {Injectable} from "@angular/core";
import {PagerParam,OrderParam,HttpHelper,Order} from "df_ng_mall_services"
@Injectable()
export class ShopOrderService{
    private ordersUrl:string="/rest/shop-manager/orders";
    public currentOrder;
    constructor(private helper:HttpHelper){

    }
    orders(pager:PagerParam,param:OrderParam):Promise<Order[]>{
        if(!pager) pager=new PagerParam;
        let url = `${this.ordersUrl}/sale?page=${pager.page}&size=${pager.size}`;
        if (param && param.step >= 3) {
            url += `&step=3&step=4&step=5`;
        }
        if (param && param.step==0) {
            url += `&step=0`;
        }
        return this.helper.getJson<Order[]>(url);
    }
    changeOrder(orderId:number){

    }


    getOrderCount(step?,today?):Promise<string> {
        let url = this.ordersUrl + `?1=1`;
        if (step) {
            url += `&step=${step}`;
        }
        if (today) {
            url += `&today=${today}`
        }
        return this.helper.getText(url);
    }


    getOrders(pager,step?,today?):Promise<Order[]> {
        let url = this.ordersUrl +`?page=${pager.page}&size=${pager.size}`;
        if (step||step === 0){
            url +=`&step=${step}`;
        }
        if (today) {
            url += `&today=${today}`;
        }
        return this.helper.getJson(url);
    }

    /**
     * 订单发货
     * @param id          订单的ID
     * @param no          订单的物流编号
     * @param company     订单的物流公司
     */
    deliverOrder(id, no, company): Promise<boolean> {
        let url = `${this.ordersUrl}/sale/${id}?no=${no}&company=${company}`;
        return this.helper.putToBoolean(url,null);
    }
    /*
    * todo 服务器暂无请求
    * */
    getOrder(id):Promise<Order> {
        let url = `${this.ordersUrl}/detail/${id}`;
        return this.helper.getJson(url);
    }
}
